package com.sto.stoapp.download;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sto.stoapp.db.manager.DataDictManager;
import com.sto.stoapp.db.manager.DownLoadDao;
import com.sto.stoapp.db.manager.EffectiveTypeManager;
import com.sto.stoapp.db.manager.FrequencyManager;
import com.sto.stoapp.db.manager.GoodsTypeManager;
import com.sto.stoapp.db.manager.NextSiteManager;
import com.sto.stoapp.db.manager.OrderReturnReasonManager;
import com.sto.stoapp.db.manager.OrgRuleManager;
import com.sto.stoapp.db.manager.ProblemManager;
import com.sto.stoapp.db.manager.RegionInfoManager;
import com.sto.stoapp.db.manager.RouteManager;
import com.sto.stoapp.db.manager.SalesManager;
import com.sto.stoapp.db.manager.ScanRuleDBManager;
import com.sto.stoapp.db.manager.SiteFullManager;
import com.sto.stoapp.db.manager.UserInfoManager;
import com.sto.stoapp.db.manager.UserManager;
import com.sto.stoapp.db.manager.UserRuleManager;
import com.sto.stoapp.http.response.download.DownLoadResponse;
import com.sto.stoapp.http.response.download.info.DatadictInfo;
import com.sto.stoapp.http.response.download.info.EffectiveTypeInfo;
import com.sto.stoapp.http.response.download.info.EmpInfo;
import com.sto.stoapp.http.response.download.info.FrequencyInfo;
import com.sto.stoapp.http.response.download.info.GoodsTypeInfo;
import com.sto.stoapp.http.response.download.info.IssueInfo;
import com.sto.stoapp.http.response.download.info.NextStopInfo;
import com.sto.stoapp.http.response.download.info.OderReturnReasonInfo;
import com.sto.stoapp.http.response.download.info.OrgInfo;
import com.sto.stoapp.http.response.download.info.OrgRuleInfo;
import com.sto.stoapp.http.response.download.info.RegionInfo;
import com.sto.stoapp.http.response.download.info.RouteInfo;
import com.sto.stoapp.http.response.download.info.ScanRuleInfo;
import com.sto.stoapp.http.response.download.info.UserInfoInfo;
import com.sto.stoapp.http.response.download.info.UserRuleInfo;

public class DownFactory {

	public static DownLoadDao getDownDao(EnunDownLoad downType, Context context) {

		if (downType == EnunDownLoad.ISSUE_TABLE)

			return ProblemManager.getInstance(context);

		else if (downType == EnunDownLoad.REGION_TABLE)
			return RegionInfoManager.getInstance(context);
		else if (downType == EnunDownLoad.ORDER_RETURN_REASON_TABLE)
			return OrderReturnReasonManager.getInstance(context);

		else if (downType == EnunDownLoad.ORG_TABLE)
			return SiteFullManager.getInstance(context);
		else if (downType == EnunDownLoad.NEXT_STOP_TABLE)
			return NextSiteManager.getInstance(context);

		/*
		 * 路由下载 RouteInfo
		 */
		else if (downType == EnunDownLoad.ROUTE_TABLE)
			return RouteManager.getInstance(context);
		else if (downType == EnunDownLoad.EMP_TABLE)
			return SalesManager.getInstance(context);
		else if (downType == EnunDownLoad.USER_INFO_TABLE)
			return UserInfoManager.getInstance(context);
		else if (downType == EnunDownLoad.USER_RULE_TABLE)
			return UserRuleManager.getInstance(context);

		else if (downType == EnunDownLoad.ORG_RULE_TABLE)
			return OrgRuleManager.getInstance(context);
		else if (downType == EnunDownLoad.DATADICT_TABLE)
			return DataDictManager.getInstance(context);
		else if (downType == EnunDownLoad.GOODS_TYPE_TABLE)
			return GoodsTypeManager.getInstance(context);
		else if (downType == EnunDownLoad.EFFECTIVE_TYPE_TABLE)
			return EffectiveTypeManager.getInstance(context);
		else if (downType == EnunDownLoad.FREQUENCY_TABLE)
			return FrequencyManager.getInstance(context);
		else if (downType == EnunDownLoad.USER_TABLE)
			return UserManager.getInstance(context);
		else if (downType == EnunDownLoad.SCAN_RULE_TABLE)
			return ScanRuleDBManager.getInstance(context);
		else
			return null;

	}

	@SuppressWarnings({ "unused", "rawtypes" })
	private DownLoadResponse getDownLoadResponse(String responseStr,
			EnunDownLoad downType) {
		Gson gson = new Gson();

		if (downType == EnunDownLoad.ISSUE_TABLE)

			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<IssueInfo>>() {
					}.getType());
		// case OFFLINE_LOGIN:
		// response = gson.fromJson(responseStr,
		// new TypeToken<DownLoadResponse<UserInfo>>() {
		// }.getType());
		//
		// // TODO: OffLineManager.insert
		// break;
		else if (downType == EnunDownLoad.REGION_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<RegionInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.ORDER_RETURN_REASON_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<OderReturnReasonInfo>>() {
					}.getType());

		else if (downType == EnunDownLoad.ORG_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<OrgInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.NEXT_STOP_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<NextStopInfo>>() {
					}.getType());

		/*
		 * 路由下载 RouteInfo
		 */
		else if (downType == EnunDownLoad.ROUTE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<RouteInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.EMP_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<EmpInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.USER_INFO_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<UserInfoInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.USER_RULE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<UserRuleInfo>>() {
					}.getType());

		else if (downType == EnunDownLoad.ORG_RULE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<OrgRuleInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.DATADICT_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<DatadictInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.GOODS_TYPE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<GoodsTypeInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.EFFECTIVE_TYPE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<EffectiveTypeInfo>>() {
					}.getType());
		else if (downType == EnunDownLoad.FREQUENCY_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<FrequencyInfo>>() {
					}.getType());

		else if (downType == EnunDownLoad.SCAN_RULE_TABLE)
			return gson.fromJson(responseStr,
					new TypeToken<DownLoadResponse<ScanRuleInfo>>() {
					}.getType());
		else
			return null;
	}
}
